import { NetInfo } from 'react-native'
import Toast from 'react-native-root-toast'
// 网络状态监听
const addNetListener = () => {
    NetInfo.addEventListener('connectionChange',handleNetChange)
 }
const handleNetChange = (connectionInfo) => {
     switch (connectionInfo){
         case 'none':
         case 'NONE':
             return Toast.show('无网络连接')
         case 'wifi':
         case 'WIFI':
         case 'cell':
         case 'MOBILE':
             return Toast.show('网络已连接')
         default:
             return null
     }
}

const getCurrentNetInfo = () => {
    return NetInfo.getConnectionInfo()
}

export {
    addNetListener,
    getCurrentNetInfo
}